FROM php:7.2-fpm

# 安装系统软件包
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && \
    apt-get -y install \
            gnupg2 \
            g++ \
            git \
            curl \
            imagemagick \
            libcurl3-dev \
            libicu-dev \
            libfreetype6-dev \
            libjpeg-dev \
            libjpeg62-turbo-dev \
            libonig-dev \
            libmagickwand-dev \
            libpq-dev \
            libpng-dev \
            libxml2-dev \
            libzip-dev \
            zlib1g-dev \
            default-mysql-client \
            openssh-client \
            nano \
            unzip \
            libcurl4-openssl-dev \
            libssl-dev \
            libmpdec-dev \
            supervisor \
            cron \
            procps \
            dos2unix \
        --no-install-recommends

# 安装PHP扩展
COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/local/bin/
RUN install-php-extensions \
    soap \
    zip \
    curl \
    bcmath \
    exif \
    gd \
    iconv \
    intl \
    mbstring \
    opcache \
    pcntl \
    posix \
    pdo_mysql \
    pdo_pgsql \
    imagick \
    decimal \
    memcached \
    redis \
    mongodb

# 安装PHP Swoole扩展
RUN printf "\n" | pecl install \
        http://pecl.php.net/get/swoole-4.8.12.tgz && \
    docker-php-ext-enable \
        swoole

RUN apt-get clean && \
    rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*


# 设置时区
ENV TIME_ZONE Asia/Shanghai
# ENV TIME_ZONE UTC
RUN echo "${TIME_ZONE}" > /etc/timezone \
    && ln -sf /usr/share/zoneinfo/${TIME_ZONE} /etc/localtime

# 设置系统编码
ENV LANG C.UTF-8
ENV LC_ALL C.UTF-8

# 允许Composer作为root运行
ENV COMPOSER_ALLOW_SUPERUSER 1

# 安装Composer
COPY ./config/usr.local.bin/composer /usr/local/bin/composer
RUN chmod 755 /usr/local/bin/composer
RUN curl -sS https://install.phpcomposer.com/installer | php -- \
        --version=2.5.4 \
        --filename=composer.phar \
        --install-dir=/usr/local/bin && \
    composer clear-cache
# 更换为阿里云镜像
RUN composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/

COPY ./config/php-fpm.conf /usr/local/etc/php-fpm.conf
COPY ./config/conf.d/ /usr/local/etc/php/conf.d/

# (Debian only) Change www-data user ID
# ENV PHP_USER_ID 1000
# RUN set -x \
#     && userdel www-data \
#     && groupadd -g ${PHP_USER_ID} -r www-data \
#     && useradd -u ${PHP_USER_ID} -r -g www-data www-data

WORKDIR /opt/htdocs

EXPOSE 9000
